package com.xnyzc.lhy.nio;

import com.alibaba.fastjson.JSON;
import com.xnyzc.lhy.common.cache.NettyChannelMap;
import com.xnyzc.lhy.common.constant.MethodConstant;
import com.xnyzc.lhy.common.util.DateUtil;
import com.xnyzc.lhy.nio.netty.NettyMsg;
import com.xnyzc.lhy.nio.netty.NettyServerService;
import com.xnyzc.lhy.order.entity.order.OaCOrderPersonal;
import io.netty.channel.ChannelHandlerContext;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@RestController
@RequestMapping("oa/nio")
public class testController {

    @PostMapping(value = "/test")
    public boolean test(){
        OaCOrderPersonal personal=new OaCOrderPersonal();
        personal.setOrderNo("123123123123");
        personal.setStartAddress("双流机场");
        personal.setEndAddress("环球中心");
        personal.setRealFlightTime(DateUtil.dateAddMinutes(new Date(),120));
        personal.setAppointment(new Date());
        Long driverId = 1823561004220416L;
        String cityId = "510100";
        ChannelHandlerContext ctx = NettyChannelMap.getData(cityId + ":" + driverId);
        if (ctx != null && !ctx.isRemoved()) {
            NettyServerService.sendMsgToClient(ctx, NettyMsg.setJsonMsg(MethodConstant.FLIGHT_CHANGED, JSON.toJSONString(personal)));
        }
        return true;
    }
}
